<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\facade\Builder;
use think\response\Json;

class TeamLevel extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\TeamLevel';

    public function index(): string
    {
        //构建表格数据
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'title' => '全选', 'fixed' => 'left'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'title', 'title' => '标题', 'modify' => '2,input'])
            ->addColumn(['field' => 'amount', 'title' => '累计收入', 'modify' => '2,input'])
            ->addColumn(['field' => 'bonus', 'title' => '管理收益', 'modify' => '2,ratio','templet' => '<span>{{(d.bonus*100).toFixed(2)}}%</span>'])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 200])
            ->addRightButtons(['edit' => ['size' => '1000,1000']])
//            ->addTopButtons(['add' => ['size' => '1000,1000'], 'deleteAll'])
            ->addSearch([
                ['title', '等级名称', 'input,Like'],
            ])
            ->addSwitchTool([])
            ->addSortTool([])
            ->fetch();
    }

    public function save($param = [], $model = false): Json
    {
        $param = $this->request->post();
        $param['bonus'] = $param['bonus'] / 100;
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }

}
